//
//  PQTabBarController.m
//  PaiQuan
//
//  Created by Mac on 16/7/5.
//  Copyright © 2016年 huigu. All rights reserved.
//

#import "PQTabBarController.h"
#import "CardCirleViewController.h"
#import "GameViewController.h"
#import "MarketViewController.h"
#import "MyViewController.h"
#import "RecordViewController.h"
#import "PQTabBar.h"
#import "PQNavigationController.h"

@interface PQTabBarController ()

@end

@implementation PQTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
   //
    [self addChildVc:[[CardCirleViewController alloc] init] title:@"牌圈" image:@"01_normal" selectedImage:@"01_heighted"];
    [self addChildVc:[[MarketViewController alloc] init] title:@"商城" image:@"02_normal" selectedImage:@"02_heighted"];
     [self addChildVc:[[GameViewController alloc] init] title:nil image:nil selectedImage:nil];
    
    [self addChildVc:[[RecordViewController alloc] init] title:@"战绩" image:@"04_normal" selectedImage:@"04_heighted"];
    [self addChildVc:[[MyViewController alloc] init] title:@"个人" image:@"05_normal" selectedImage:@"05_heighted"];
    
    PQTabBar *tabBar =  [[PQTabBar alloc] init];
    tabBar.delegate = self;
    [self setValue:tabBar forKey:@"tabBar"];
    
    
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
/**
 *  添加一个子控制器
 *
 *  @param childVc       子控制器
 *  @param title         标题
 *  @param image         图片
 *  @param selectedImage 选中的图片
 */

- (void)addChildVc:(UIViewController *)childVc title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage
{
    // 设置子控制器的文字(可以设置tabBar和navigationBar的文字)
    childVc.title = title;
    
    // 设置子控制器的tabBarItem图片
    childVc.tabBarItem.image = [UIImage imageNamed:image];
    // 禁用图片渲染
    childVc.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImage] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    // 设置文字的样式
    [childVc.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName :[UIColor whiteColor]} forState:UIControlStateNormal];
    [childVc.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName : PQ_COLOR_YELLOW} forState:UIControlStateSelected];
    //    childVc.view.backgroundColor = RandomColor; // 这句代码会自动加载主页，消息，发现，我四个控制器的view，但是view要在我们用的时候去提前加载
    
    // 为子控制器包装导航控制器
  PQNavigationController  *navigationVc = [[PQNavigationController alloc] initWithRootViewController:childVc];
    // 添加子控制器/Users/mac/Desktop/QiPai/PaiQuan/PaiQuan/Classes/Main/PQTabBarController.m
    [self addChildViewController:navigationVc];
}





@end
